<?php
/*
 * 手机客户端 支付商品选择接口
 * 2013-12-03
 */
 
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数


$aids 			= $_REQUEST["aid"];				//商品id，多个用逗号分割
$province		= $_REQUEST["province"];		//省份

if(!$aids){
	$aids = "0"; //放一个默认值
}

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键

$reJson = array(); //构建返回值

$carriage = 0; //运费
if($province){
	//计算运费
	$sql = "select sum(aweight) as total_weight from auction where aid in (".$aids.")";
	$db->query($sql);
	$db->next_record();
	$tweight = $db->f("total_weight"); //总重量
	
	$sql="call pro_get_yunfei('".$tweight."','".$province."',@x)";
	$db->query($sql);
	$db->query("select @x");
	if($db->next_record()){
		$carriage = $db->f("@x");
	}	
}

//获取物流配送信息
$sql = "select shipping_id,shipping_name from set_shipping order by shipping_id desc";
$db->query($sql);
$despatchType = array(); //配送方式
while($db->next_record()){
	$despatchType[] = array(
		"key"=>$db->f("shipping_id")
		,"value"=>$db->f("shipping_name")
	);
}

//查询拍品信息
$sql = "select
			a.aulbid,
			a.aid,
			b.acode,
			b.auction,
			b.endtime,
			date_add(b.endtime,interval 14 day) as limitime,
			a.bid,
			b.servicefee
		from
			auction_userlastbid a
			inner join auction b on b.aid = a.aid
		where 
			a.is_bid=1 
			and a.uid='".$uid."'
			and b.aid in (".$aids.")";
			
$total_fwf = 0; 		//总共服务费
$total_count = 0;		//拍品数量
$total_amount = 0;		//总价格
$goodsList = array();	//拍品名称数组
$db->query($sql);
while($db->next_record()){
	$total_count++;
	$bid_fee = $db->f("servicefee")*0.01*$db->f("bid");
	$total_fwf = $total_fwf + $bid_fee;
	$total_amount = $total_amount+$db->f("bid");
	$goodsList[] = $db->f("auction");
}
//积分：总金额除以100，作为显示用的积分
$points = (int)$total_amount / 100;

$reJson = array(
	"success"=>"1"
	,"order"=>array(
		"carriage"=>(string)$carriage
		,"payType"=>array(array("key"=>"6","value"=>"银联支付"))
		,"goodsList"=>$goodsList
		,"count"=>(string)$total_count
		,"money"=>(string)$total_amount
		,"points"=>(string)(int)$points
		,"needPay"=>(string)($total_amount+$carriage+$total_fwf)
		,"serviceCharge"=>(string)$total_fwf
		,"despatchType"=>$despatchType
	)
);
echo json_encode($reJson);
 ?>